package com.qf.test;

import com.qf.service.UserService;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * @author zjw
 * @description 当前类为JDK动态代理类，需要通过当前类，代理UserServiceImpl
 * @date 2021/9/28$ 16:08$
 */
public class JDKDynamicProxy implements InvocationHandler {

    private UserService userService;

    public JDKDynamicProxy(UserService userService) {
        this.userService = userService;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        // 记录日志
        System.out.println("记录日志！！！");

        // 执行原方法
        Object result = method.invoke(userService, args);

        return result;
    }
}
